package com.example.jiaju.adapter;

import android.content.Context;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.jiaju.R;
import com.example.jiaju.entity.FurnitureTheme;
import java.util.List;
public class FurnitureThemeAdapter extends RecyclerView.Adapter<FurnitureThemeAdapter.MyViewHolder> {
    private List<FurnitureTheme> furnitureThemeList;
    private Context context;
    public FurnitureThemeAdapter(List<FurnitureTheme> furnitureThemeList,Context context) {
        this.furnitureThemeList = furnitureThemeList;
        this.context=context;
    }
    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).
                inflate(R.layout.furniture_theme_item,parent,false);
        return new MyViewHolder(view);
    }
    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        //添加数据 等API
        holder.furnitureThemeName.setText(furnitureThemeList.get(position).getFurnitureThemeName());
        Glide.with(context).load(furnitureThemeList.get(position).getFurnitureThemeImg()).into(holder.furnitureThemeImg);
    }
    @Override
    public int getItemCount() {
        return furnitureThemeList.size();
    }
    static class MyViewHolder extends RecyclerView.ViewHolder{
        private ImageView furnitureThemeImg;
        private TextView furnitureThemeName;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            furnitureThemeImg=itemView.findViewById(R.id.furniture_theme_img);
            furnitureThemeName=itemView.findViewById(R.id.furniture_theme_name);
        }
    }
}
